<?php


namespace App\Services;


use App\Order;
use Carbon\Carbon;

class RefundService
{
     public function refund($order_id,$des="商品已售完")
     {
         $app=app('wechat.payment');
         $order=Order::where('order_number',$order_id)->first();
         $refund_number="T".Carbon::now()->format('YmdHis') . random_int(1000, 9999) . $order->uid;
// 参数分别为：微信订单号、商户退款单号、订单金额、退款金额、其他参数
         $result=$app->refund->byTransactionId($order->merchant_number,$refund_number,floatval($order->pay_amount)*100, floatval($order->pay_amount)*100,[ 'refund_desc' => $des]);
         if ($result['return_code']=="SUCCESS"){
             return $refund_number;
         }else{
             return false;
         }

     }
}
